implement tableNode:nodeForRowAtIndexPath: execution thread#14
Conversation
|
Hi @fumito-ito , AFAIK RxSwift |
|
@dangthaison91 thanks ! I will check it later ! |
a2d26a5 to
306c939
Compare
tableNode:nodeForRowAtIndexPath: execution threadtableNode:nodeForRowAtIndexPath: execution thread
|
I used |
|
Sorry @fumito-ito , my health has gone bad for weeks. Will be back this weekend. |
|
@dangthaison91 I understand. Get well soon ! |
| fileprivate static func configureCellBlockNotSet(dataSource: ASTableSectionedDataSource<S>, node: ASTableNode, indexPath: IndexPath, model: I) -> ASCellNodeBlock { | ||
| return { dataSource.tableNode(node, nodeForRowAt: indexPath) } | ||
| // Users expect taleNode(_:nodeForRowAt:) will be executed in main thread according to api doc http://texturegroup.org/appledoc/Protocols/ASTableDataSource.html#//api/name/tableNode:nodeForRowAtIndexPath: . | ||
| return { DispatchQueue.main.sync(execute: { dataSource.tableNode(node, nodeForRowAt: indexPath) }) } |
There was a problem hiding this comment.
IMHO, Binder using in RxASTableNodeReloadDataSource already guarantee that datasource is executed on Main Thread.
Could you help to verify that by using another DispatchQueue in Example app.
There was a problem hiding this comment.
@dangthaison91 Sorry for delay.
configureCellBlockNotSet may be executed in tableNode(_ tableNode:nodeBlockForRowA:) -> ASCellNodeBlock and this delegate is NOT called in main thread but called in background thread.
Following sentences are from Texture API Doc.
– tableNode:nodeBlockForRowAtIndexPath:
Asks the data source for a block to create a node to represent the row at the given index path.
The block will be run by the table node concurrently in the background before the row is inserted into the table view.
There was a problem hiding this comment.
@fumito-ito @dangthaison91
I don't think this is best solution.
tableNode:nodeForRowAt:
tableNode:nodeBlockForRowAt:
will always execute in main thread.
because ASDK will check execution thread in ASDataController by ASDisplayNodeAssertMainThread().
but ASNodeBlock() will be execute concurrently in background .
So, see the Rx logic, if we not set configureCellBlock, it will fall back by embed tableNode:nodeForRowAt: in configureCellBlockNotSet, It will cause tableNode:nodeForRowAt: execute in background thread.
Actually, without RxASDataSOurce, if you want init node at main thread, you should just implement tableNode:nodeForRowAt: and ignore tableNode:nodeBlockForRowAt:, but both of them implement in Rx, I guess this is why we use configureCellBlockNotSet function.
in the end, this is my solution:
let cellNode = dataSource.tableNode(node, nodeForRowAt: indexPath)
return { cellNode }
There was a problem hiding this comment.
Thank you for your comment @PatrickChow .
Your solution looks same as return { dataSource.tableNode(node, nodeForRowAt: indexPath) }. Do you mean this change is not needed ?
There was a problem hiding this comment.
Oh I found the difference. According to your solution, let cellNode = dataSource.tableNode(node, nodeForRowAt: indexPath) is called in main thread but { cellNode } will be executed in background.
|
@dangthaison91 add update for |
Any update on this PR, i'm having issues with the threading of configureCell in |
|
@foxware00 Could you help direct your pod to @fumito-ito repo for this PR and help to verify if this PR will resolve your issues with |
|
@fumito-ito Are you still working on this PR? |
|
@dangthaison91 hi! I catch up the comment from @PatrickChow #14 (comment) . |
According to API doc,
tableNode:nodeForRowAtIndexPath:should be called on main thread.